package com.chinanet.netelementmodel;


import com.chinanet.entry.netelement.Attr;
import com.chinanet.entry.netelement.AttrType;
import com.chinanet.entry.netelement.WorkInterFace;
import com.chinanet.utils.telnet.ITelnet;
import com.chinanet.utils.telnet.Socket2Telnet;

import java.net.Socket;
import java.util.Map;
/**
 * ZX_Mmtel_Query_EB_Imp
 * 中兴IMS-mmtel网元-查询补充业务命令
 * @author zyd
 * SHOW OSU SBRSRV:PUI="tel:+8657688910054";
 *
 */
public class ZX_Mmtel_Query_EB_Imp implements WorkInterFace {

	@Override
	public String getName() {
		return "查询补充业务命令";
	}

	@Override
	public String getDesciption() {
		return "测试方法";
	}

	@Override
	public int getVersion() {
		return 0;
	}

	@Override
	public Attr[] getInAttrs() {
		Attr[] in = new Attr[1];
//		in[0] = new Attr("tbIpAddress", "跳板机的ip地址", AttrType.TYPE_String, true);
//		in[1] = new Attr("tbUsername", "跳板机登录用户名", AttrType.TYPE_String, true);
//		in[2] = new Attr("tbPassword", "跳板机登录密码", AttrType.TYPE_String, true);
//		in[3] = new Attr("switchboardIpAddress", "交换机的ip地址", AttrType.TYPE_String, true);
//		in[4] = new Attr("switchboardUsername", "交换机登录用户名", AttrType.TYPE_String, true);
//		in[5] = new Attr("switchboardPassword", "交换机登录密码", AttrType.TYPE_String, true);
		in[0] = new Attr("command", "查询指令", AttrType.TYPE_String, true);
		return in;
	}

	@Override
	public Attr[] getOutAttrs() {
		Attr[] out = new Attr[2];
		out[0] = new Attr("result", "查询结果", AttrType.TYPE_String, true);
		out[1] = new Attr("log", "日志文件", AttrType.TYPE_String, true);
		return out;
	}

	@Override
	public Map<String, Object> init(Map<String, Object> data) {
		String param = ITelnet.getInputPhoneFormat(data.get("command").toString());
		Socket2Telnet s = new Socket2Telnet(new Socket(), "134.96.213.68", 21123);
		s.getIns().add("tz.skb");
		s.getIns().add("tz.skb111");
		s.getIns().add("SET AMO:NAME=\"HZMMTEL202-SSS_141\"");
		s.getIns().add("get");
		s.getIns().add("SHOW OSU SBRSRV:PUI=\""+param+"\"");
		s.setProp("$HZMMTEL202-SSS_141>");
		s.run();
		if (s.getResult() != null) {
			System.out.println("成功获取数据");
		} else {
			System.out.println("发生错误");
		}
		Map<String, Object> outmap;
		String pattern = "\\S+\\s+\\|[\\S+\\s+\\|]+\\S+\\s+\\n";
		// 将结果进行格式化
		String result = s.getResult().toString();
		outmap = ITelnet.matchingTable(pattern, result);
		outmap.put("log",s.getResult().toString());
		return outmap;
	}

}
